package com.djakapm.markdown.editor.util;

import com.djakapm.markdown.editor.AppConstant;
import com.djakapm.swing.common.IconManager;
import com.djakapm.swing.common.IconModel;

import javax.swing.*;
import java.io.IOException;

public class ResourceManager {
    private static IconManager iconManager = new IconManager();
    private static String BASE_PATH = System.getProperty("user.dir") + System.getProperty("file.separator");

    public static void init(){
        try {
            IconManager.VERBOSE = true;
            iconManager.addIcon(BASE_PATH + AppConstant.OPEN_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.NEW_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.SAVE_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.UNDO_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.REDO_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.COPY_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.CUT_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.PASTE_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.COPY_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.VIEW_CODE_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.EXIT_ICON);
            iconManager.addIcon(BASE_PATH + AppConstant.UPDATE_VIEW_ICON);

        } catch (IOException e) {
            ExceptionConsumer.consume(e);
        }
    }

    public static Icon getIcon(String iconName){
        IconModel iconModel = iconManager.getIcon(iconName);
        return iconModel == null ? null : iconModel.getIcon();
    }
}
